<div id="network-supply-custom-bar6" style="height: 100%">

</div>

<script type="text/javascript">
    $(function () {
        loadbar6("","");
        $("select#prjId").change(function(){
            document.getElementById("loading").style.display="";
            setoption6();
            loadbar6($("#prjId").val(),"");
        });
        $("select#orderType").change(function(){
            document.getElementById("loading").style.display="";
            loadbar6($("#prjId").val(),$("#orderType").val());
        });
    });
    function setoption6() {
        var center=$("#prjId").val();
        $.ajax({
            url: "#springUrl('/network/supply/custom/option6')",
            data: {"center": center},
            type: "POST",
            success: function (text) {
                var d = JSON.parse(text);
                if (d.success && d.data) {
                    $("#orderType").empty();
                    var options6="<option value=''>"+"请选择售达方"+"</option>";;
                    $("#orderType").append(options6);
                    for(var i=0;i<d.data.option6.length;i++){
                        var orderType=d.data.option6[i].orderType;
                        var options="<option value='"+orderType+"'>"+orderType+"</option>";
                        $("#orderType").append(options);
                    }
                }
            }
        })
    }
    function loadbar6(center,orderType) {
        var myChart = echarts.init(document.getElementById('network-supply-custom-bar6'), 'macarons');
        $.ajax({
            url: "#springUrl('/network/supply/custom/bar6')",
            data: {"center": center,"orderType":orderType},
            type: "POST",
            success: function (text) {
                var d = JSON.parse(text);
                if (d.success && d.data) {
                    option = {
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'cross',
                                crossStyle: {
                                    color: '#998492'
                                }
                            },

                        },
                        grid: {
                            left: '3%',
                            right: '8%',
                            bottom: '15%',
                            top:'10%',
                            containLabel: true
                        },
                        title: {
                            text: '不同订单类型的订单总数量',
                            subtext: '纯属虚构',
                            top: 10,
                            left: 10,
                            show:false
                        },
                        xAxis: [
                            {
                                type: 'category',
                                data: d.data.data1,
                                axisLabel: {
                                    textStyle:{
                                        color:"#595959"
                                    }
                                },
                                axisLine: {
                                    show: false
                                },
                                axisTick: {
                                    show: false
                                },
                            }
                        ],
                        yAxis: [
                            {
                                type: 'value',
                                name: '订单量',
                                axisLine: {
                                    show: false
                                },
                                axisTick: {
                                    show: false
                                },
                                axisLabel: {
                                    formatter: function(value){
                                        var var1=value*1;
                                        return var1;
                                    },
                                    textStyle:{
                                        color:"#595959"
                                    }
                                },
                                splitLine:{
                                    show:true
                                },
                                splitArea: {
                                    show:true,
                                    areaStyle: {
                                        color: ['rgba(0,0,0,0)', 'rgba(0,0,0,0)']
                                    }
                                },
                            },
                            {
                                type: 'value',
                                name: '订货频次',
                                axisLine: {
                                    show: false
                                },
                                axisTick: {
                                    show: false
                                },
                                axisLabel: {
                                    formatter: function(value){
                                        var var1=value*1;
                                        return var1;
                                    },
                                    textStyle:{
                                        color:"#595959"
                                    }
                                },
                                splitLine:{
                                    show:false
                                },
                                splitArea: {
                                    show: true,
                                    areaStyle: {
                                        color: ['rgba(0,0,0,0)', 'rgba(0,0,0,0)']
                                    }
                                },
                            }
                        ],
                        series: [
                            {
                                name:'订单量',
                                type:'bar',
                                data:d.data.data2,
                                itemStyle: {
                                    normal: {
                                        color: function(params) {
                                            var colorList = [
                                                '#0fa99d','#d9d9d9','#787473','#c9eee7','#e7a14c',
                                                '#4472c4','#9BCA63','#FAD860','#F3A43B','#60C0DD',
                                                '#D7504B','#C6E579','#F4E001','#F0805A','#26C0C0'
                                            ];
                                            return colorList[params.dataIndex]
                                        },
                                    }
                                    },
                                barWidth:20,
                            },
                            {
                                name:'频次',
                                type:'line',
                                yAxisIndex: 1,
                                data:d.data.data3
                            }
                        ]
                    };
                    myChart.setOption(option);
                    document.getElementById("loading").style.display="none";
                  /*  myChart.on('click',function(object){
                        // 销毁之前的echarts实例
                        echarts.dispose(document.getElementById("network-supply-custom-bar6"));
                        // 初始化一个新的实例
                        var myChart = echarts.init(document.getElementById("network-supply-custom-bar6"));
                        $.ajax({
                            url: "#springUrl('/network/supply/custom/bar61')",
                            data: {"center": center, "orderType": orderType,"sales":object.name},
                            type: "POST",
                            success: function (text) {
                                var d = JSON.parse(text);
                                if (d.success && d.data) {
                                    option1 = {
                                        color: ['#3398DB'],
                                        tooltip : {
                                            trigger: 'axis',
                                            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                                                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                                            }
                                        },
                                        grid: {
                                            left: '3%',
                                            right: '4%',
                                            bottom: '3%',
                                            containLabel: true
                                        },
                                        xAxis : [
                                            {
                                                type : 'category',
                                                data : d.data.data1,
                                                axisTick: {
                                                    alignWithLabel: true
                                                }
                                            }
                                        ],
                                        yAxis : [
                                            {
                                                type : 'value'
                                            }
                                        ],
                                        series : [
                                            {
                                                name:'订单量',
                                                type:'bar',
                                                barWidth: '60%',
                                                data:d.data.data2,
                                            }
                                        ]
                                    };

                                    myChart.setOption(option1, true);
                                }
                            },

                        });

                    });*/

                }
                else{
                    $("#loading").hide();
                    var div1="<div type='text' style='padding-top:15%' class=' text-center '>"+d.message+"</div>";
                    $("#network-supply-custom-bar6").empty();
                    $("#network-supply-custom-bar6").prepend(div1);
                }
            }
        });


        $('#return-button').on('click',function(){
            var myChart = echarts.init(document.getElementById("network-supply-custom-bar5"));
            var center=$("#prjId").val();
            var primarySales=$("#primarySales1").val();
            $.ajax({
                url: "#springUrl('/network/supply/custom/bar5')",
                data: {"center": center, "primarySales": primarySales},
                type: "POST",
                success: function (text) {
                    var d = JSON.parse(text);
                    if (d.success && d.data) {
                        option2 = {
                            tooltip: {
                                trigger: 'axis',
                                axisPointer: {
                                    type: 'cross',
                                    crossStyle: {
                                        color: '#998492'
                                    }
                                },

                            },
                            grid:{
                                x:45,
                                y:40,
                                x2:50,
                                y2:40, borderWidth:10
                            },
                            title: {
                                text: '不同订单类型的订单总数量',
                                subtext: '纯属虚构',
                                top: 10,
                                left: 10,
                                show:false
                            },
                            xAxis: [
                                {
                                    type: 'category',
                                    data: d.data.data1,
                                    axisPointer: {
                                        type: 'shadow'
                                    },
                                    axisLabel:{
                                        show:false
                                    }
                                }
                            ],
                            yAxis: [
                                {
                                    type: 'value',
                                    name: '订单量',
                                    axisLabel: {
                                        //formatter: '{value} 件'
                                    },
                                    splitLine:{
                                        show:false
                                    },
                                    splitArea: {
                                        show: true,
                                        areaStyle: {
                                            color: ['rgba(0,0,0,0)', 'rgba(0,0,0,0)']
                                        }
                                    },
                                },
                                {
                                    type: 'value',
                                    name: '订货频次',
                                    axisLabel: {
                                        //  formatter: '{value} 次'
                                    },
                                    splitLine:{
                                        show:false
                                    },
                                    splitArea: {
                                        show: true,
                                        areaStyle: {
                                            color: ['rgba(0,0,0,0)', 'rgba(0,0,0,0)']
                                        }
                                    },
                                }
                            ],
                            series: [
                                {
                                    name:'订单量',
                                    type:'bar',
                                    data:d.data.data2,
                                    itemStyle: {
                                        normal: {
                                            //好，这里就是重头戏了，定义一个list，然后根据所以取得不同的值，这样就实现了，
                                            color: function(params) {
                                                // build a color map as your need.
                                                var colorList = [
                                                    '#C1232B','#B5C334','#FCCE10','#E87C25','#27727B',
                                                    '#FE8463','#9BCA63','#FAD860','#F3A43B','#60C0DD',
                                                    '#D7504B','#C6E579','#F4E001','#F0805A','#26C0C0'
                                                ];
                                                return colorList[params.dataIndex]
                                            },
                                            //以下为是否显示，显示位置和显示格式的设置了
                                        }}},
                                {
                                    name:'频次',
                                    type:'line',
                                    yAxisIndex: 1,
                                    data:d.data.data3
                                }
                            ]
                        };
                        myChart.setOption(option2);
                        myChart.on('click',function(object){
                            $.ajax({
                                url: "#springUrl('/network/supply/custom/bar51')",
                                data: {"center": center, "primarySales": primarySales,"months":object.name},
                                type: "POST",
                                success: function (text) {
                                    var d = JSON.parse(text);
                                    if (d.success && d.data) {
                                        option3 = {
                                            color: ['#3398DB'],
                                            tooltip : {
                                                trigger: 'axis',
                                                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                                                    type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                                                }
                                            },
                                            grid: {
                                                left: '3%',
                                                right: '4%',
                                                bottom: '3%',
                                                containLabel: true
                                            },
                                            xAxis : [
                                                {
                                                    type : 'category',
                                                    data : d.data.data1,
                                                    axisTick: {
                                                        alignWithLabel: true
                                                    }
                                                }
                                            ],
                                            yAxis : [
                                                {
                                                    type : 'value'
                                                }
                                            ],
                                            series : [
                                                {
                                                    name:'直接访问',
                                                    type:'bar',
                                                    barWidth: '60%',
                                                    data:d.data.data2,
                                                }
                                            ]
                                        };

                                        myChart.setOption(option3, true);
                                    }
                                },

                            });
                        });
                    }
                }
            })


        });

    }




</script>